import Vue from 'vue';
import VueRouter from 'vue-router';
// 导入 WorkDetail 组件
import WorkDetail from '../views/WorkDetail.vue'; 

// 保存原始的 VueRouter.prototype.push 方法
const originalPush = VueRouter.prototype.push;

// 重写 VueRouter.prototype.push 方法
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => {
        // 只处理路由重复跳转的错误
        if (err.name === 'NavigationDuplicated') {
            return err;
        }
        // 其他错误继续抛出
        throw err;
    });
};

Vue.use(VueRouter);

const routes = [
    {
        path: '/',
        redirect: '/login' // 添加重定向规则
    },
    {
        path: '/login',
        name: 'Login',
        meta: { name: '登录' },
        component: () => import('../views/Login.vue')
    },
    {
        path: '/register',
        name: 'Register',
        meta: { name: '注册' },
        component: () => import('../views/Register.vue')
    },
    {
        path: '/index',
        name: 'Index',
        meta: { name: '首页' },
        component: () => import('../views/index.vue')
    },
    {
        path: '/concern',
        name: 'Concern',
        meta: { name: '关注' },
        component: () => import('../views/Concern.vue')
    },
    {
        path: '/friend',
        name: 'Friend',
        meta: { name: '朋友' },
        component: () => import('../views/Friend.vue')
    },
    {
        path: '/mind',
        name: 'Mind',
        meta: { name: '我的' },
        component: () => import('../views/Mind.vue')
    },
    {
        path: '/setting',
        name: 'Setting',
        meta: { name: '设置' },
        component: () => import('../views/Setting.vue')
    },
    {
        path: '/work/detail/:id',
        name: 'WorkDetail',
        component: WorkDetail
    },
    {
      path: '/UserProfile',
      name: 'UserProfile',
      meta: { name: '设置' },
      component: () => import('../views/Others.vue')
  },
    // {
    //     path: '/fb',
    //     name: 'Fb',
    //     meta: { name: '发布' },
    //     component: () => import('../views/Fb.vue')
    // },
];

const router = new VueRouter({
    // 指定路由模式为 history
    mode: 'history', 
    routes
});

export default router;    